package com.genius.unite_platform.haocai.service.impl;



import java.sql.SQLException;
import java.util.HashMap;

import javax.servlet.http.HttpSession;

import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSourceType;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.genius.adminmanager.other.entity.FillAddJson;
import com.genius.adminmanager.other.entity.ResponseJson;
import com.genius.dingding.util.GeniusConfig;
import com.genius.dingding.util.HttpHelper;
import com.genius.unite_platform.haocai.service.HaocaiServiceAdapter;
import com.genius.workflow.page.PageResult;
import com.genius.workflow.page.SearchResult;
import com.genius.workflow.page.SqlLang;
import com.genius.workflow.util.ConnectionException;
import com.genius.workflow.util.DBClosedException;
import com.genius.workflow.util.DBTools;
import com.genius.workflow.util.DBTools2;


@Service("haocaiSelectService")
public class HaocaiSelectServiceImpl extends HaocaiServiceAdapter{
	@Override
	public JSONObject InventoryGoods(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryGoods?StoreNO="+json.getString("StoreNO");
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject getmendian(JSONObject json, JSONObject response, HttpSession session) {
		int type = json.getInteger("type");
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryStore?type="+type;
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject getmendian_hc(JSONObject json, JSONObject response, HttpSession session) {
		int type = json.getInteger("type");
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryStore_HC?type="+type;
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pdstart(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryStart";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pdstart_hc(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryStart_HC";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pdfinish(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryEnd";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
			if("1".equals(resultStr)){
				response.put(ResponseJson.msg, "修改成功");
			}else{
				response.put(ResponseJson.msg,"修改失败");
			}
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pdfinish_hc(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryEnd_HC";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
			if("1".equals(resultStr)){
				response.put(ResponseJson.msg, "修改成功");
			}else{
				response.put(ResponseJson.msg,"修改失败");
			}
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pdcancel(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryEnd";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
			if("1".equals(resultStr)){
				response.put(ResponseJson.msg, "修改成功");
			}else{
				response.put(ResponseJson.msg,"修改失败");
			}
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pdcancel_hc(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryEnd_HC";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
			if("1".equals(resultStr)){
				response.put(ResponseJson.msg, "修改成功");
			}else{
				response.put(ResponseJson.msg,"修改失败");
			}
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pdsave(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventorySave";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
        	System.out.println("resultStr"+resultStr);
        	
        	
			if("1".equals(resultStr)){
				response.put(ResponseJson.msg, "参数修改成功");
			}else{
				response.put(ResponseJson.msg, "修改失败");
			}
			
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pdsave_hc(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventorySave_HC";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
			if("1".equals(resultStr)){
				response.put(ResponseJson.msg, "参数修改成功");
			}else{
				response.put(ResponseJson.msg, "修改失败");
			}
			
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pandianchaxvn(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryStoreDiff";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject pandianchaxvn_hc(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryStoreDiff_HC";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject InventorySelect(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventorySelect?Paper="+json.getString("PaperNO");
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	
	@Override
	public JSONObject InventoryEdit(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryEdit?Paper="+json.getString("PaperNO");
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	
	
	@Override
	public JSONObject InventorySelect_hc(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventorySelect_HC?Paper="+json.getString("PaperNO");
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	
	
	@Override
	public JSONObject InventoryEdit_hc(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryEdit_HC?Paper="+json.getString("PaperNO");
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	
	
	@Override
	public JSONObject InventoryStoreDiffDtl(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryStoreDiffDtl?Paper="+json.getString("PaperNO");
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject InventoryStoreDiffDtl_hc(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/InventoryStoreDiffDtl_HC?Paper="+json.getString("PaperNO");
        try {
        	String resultStr = HttpHelper.httpGetString(url);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
	@Override
	public JSONObject getusername(JSONObject json, JSONObject response) {   
	try {
    		JSONObject addJson = new JSONObject();
    		String selectField = "userId,username,name";
    		String whereField = "userId";
    		String table = "t_user";
			HashMap<String, String> sqlMap = new HashMap<>();
			JSONObject fillJson = new JSONObject();
			addJson = DBTools.getFilling(selectField,whereField,table,json,addJson);
			JSONObject fillEditJson = DBTools.getFilling(sqlMap);
			fillJson.put(FillAddJson.field, addJson);
			fillJson.put(FillAddJson.select, fillEditJson);
			response.put(ResponseJson.status, ResponseJson.status_Success);
			response.put(ResponseJson.msg, ResponseJson.msg_Add_Data_Success);
			response.put(ResponseJson.data,fillJson);
		}  catch (ConnectionException e) {
			response.put(ResponseJson.status, ResponseJson.status_Failed);
    		response.put(ResponseJson.msg, ResponseJson.msg_No_Porwer_Query_Field);
		} catch (DBClosedException e) {
			response.put(ResponseJson.status, ResponseJson.status_Failed);
    		response.put(ResponseJson.msg, ResponseJson.msg_DB_Closed_Failed);
		} catch (SQLException e) {
			response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Edit_Fill_Data_Error);
		}
		return response;
	}
	@Override
	public JSONObject StockSelect(JSONObject json, JSONObject response, HttpSession session) {
		String url = "http://39.107.83.199:8045/api/EditGoodsClass/StockSelect";
        try {
        	String resultStr = HttpHelper.httpPostMethodString(url, json);
        	JSONArray jsonArray= JSONArray.parseArray(resultStr);
        	response.put(ResponseJson.data, jsonArray);
        } catch (Exception e) {
            response.put(ResponseJson.status, ResponseJson.status_Failed);
			response.put(ResponseJson.msg, ResponseJson.msg_Query_Data_Error);
        } 
		return response;
	}
}
